<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:49:"D:\www\tp7./application/houtai\view\cate\lst.html";i:1503645492;s:54:"D:\www\tp7./application/houtai\view\public\header.html";i:1504938710;}*/ ?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title>樱桃的站点后台管理系统</title>  
<link rel="shortcut icon" href="__INDEX__/images/favicon.ico">
<link rel="stylesheet" href="__HOUTAI__/css/pintuer.css">
<link rel="stylesheet" href="__HOUTAI__/css/admin.css">

<script src="__HOUTAI__/js/jquery-2.1.4.min.js"></script>
<script src="__HOUTAI__/js/layer.js"></script>


<script src="__HOUTAI__/js/jquery.validate.js"></script>
<script src="__HOUTAI__/js/additional-methods.js"></script>
<script src="__HOUTAI__/js/messages_zh.js"></script>
<!-- 字体图标文件CSS -->
<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_394272_s1c3jukr7t10dx6r.css">
<!-- 字体图标文件js -->
<script type="text/javascript" src="//at.alicdn.com/t/font_394272_s1c3jukr7t10dx6r.js"></script>


<!-- <script type="text/javascript" src="http://malsup.github.io/jquery.form.js"></script> -->

</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong class="icon-menu"> 栏目列表</strong></div>
  <div class="padding border-bottom">
    <a href="javascript:;" type="button" class="button border-yellow" onclick="openifram('添加栏目','60%','400px','<?php echo url('cate/add'); ?>')"><span class="icon-tianjia"></span> 添加栏目</a>
    <a href="javascript:void(0)" class="button border-blue icon-paixu1" onclick="sorts()"> 排序</a>
    <button type="button"  class="button border-green" id="checkall"><span class="icon-xuanze"></span> 全选</button>
    <button type="submit" class="button border-red" onclick="delall()" id="checkdel"><span class="icon-shanchu"></span> 批量删除</button>
    <button type="submit" class="button border-red" onclick="Emptied()" id="checkdel"><span class="icon-ziyuan"></span> 清空</button>
  </div>
  <table class="table table-hover text-center">
    <tr>
      <th width="5%">ID</th>
      <th width="10%">排序</th>
      <th width="15%">一级分类</th>
      <th width="10%">栏目属性</th>
      <th width="10%">操作</th>
    </tr>
    <?php if(is_array($cate) || $cate instanceof \think\Collection || $cate instanceof \think\Paginator): $i = 0; $__LIST__ = $cate;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
    <tr>
      <td><input type="checkbox" name="id[]" value="<?php echo $vo['id']; ?>"><?php echo $vo['id']; ?></td>
      <td><input type="text" name="<?php echo $vo['id']; ?>" value="<?php echo $vo['sort']; ?>" title="<?php echo $vo['id']; ?>" id="sorts" style="width: 30px;"></td>
      <td><?php echo $vo['name_display']; ?></td>
      <td><?php echo cate_types($vo['sf']); ?></td>
      <td>
        <div class="button-group"> 
          <a class="button border-main" href="javascript:;" onclick="openifram('修改栏目','60%','400px','<?php echo url('cate/edit',['id'=>$vo['id']]); ?>')"><span class="icon-xiugai"></span> 修改</a> 
          <a class="button border-red" href="javascript:void(0)" onclick="system_category_del(this,<?php echo $vo['id']; ?>)"><span class="icon-shanchu"></span> 删除</a>
      </div></td>
    </tr>
    <?php endforeach; endif; else: echo "" ;endif; ?>
  </table>
</div>
<script type="text/javascript">
// 排序
function sorts(){
  var array=[];
  $("input[type='text']").each(function(){
    array.push({
      'id':$(this).prop("name"),
      'sort' : $(this).val(),
    })
  });
  console.log(array);
  $.ajax({
    type:"POSt",
    url:"<?php echo url('cate/sorts'); ?>",
    data:{
      array,
      // 'id':sorids,
    },
    success:function(data){
      var data=eval("("+data+")");
      if (data.status) {
        parent.layer.msg('排序成功~！',{icon:1,time:1000,},function(){parent.location.reload();});
      }else{
        parent.layer.msg('排序失败~！',{icon:2,time:1000,},function(){parent.location.reload();});
      }
    }
  });
}

// 全选
jQuery(function($){
  //全选 
  $("#checkall").click(function(){ 
      $("input[name='id[]']").attr("checked","true"); 
      // $("input[name='checkbox']:checkbox:checked").each(function(){ 
      //     aa.push($(this).val());
      // })
      // console.log(aa);
      // aa= new Array();
  })
})
function delall(){
  layer.confirm('是否全部删除',function(){
    var ids= new Array(); 
    $("input[name='id[]']:checkbox:checked").each(function(){ 
      ids.push($(this).val());
    });
    var idj=ids.join(",")
    // alert(idj);
    $.ajax({
      type:"GET",
      url:"<?php echo url('cate/delall'); ?>",
      data:{
        'id':idj,
      },
      success:function(data){
        var data=eval("("+data+")");
        if (data.status) {
          parent.layer.msg('删除成功~！',{icon:1,time:1000,},function(){parent.location.reload();});
        }else{
          parent.layer.msg('删除失败~！',{icon:2,time:1000,},function(){parent.location.reload();});
        }
      }
    })
  });
}

// 单个删除
function system_category_del(obj, id) {

  layer.confirm('确认要删除吗？', function (index) {

    $.ajax({
        type: "POST",
        url: "<?php echo url('cate/del'); ?>",
        data: {
        'id':id,
        },
        dataType: "json",
        success: function(data){
          var data=eval("("+data+")");

        if (data.status){

          parent.layer.msg('删除成功~！',{icon:1,time:1000,},function(){parent.location.reload();});
        
        }
        else{
        parent.layer.msg('删除失败~！',{icon:2,time:1000,},function(){parent.location.reload();});
        }
        }
      });
    });
}
// 弹窗
function openifram(title,width,height,url){
    layer.open({
      type: 2,
      title: title,
      fixed:false,
      area: [width, height],
      shade: [0.2, '#393D49'],
      maxmin: true,
      content: url,
  });
}
// 当前数据表清空炒作
function Emptied(){
  layer.confirm('确定要清空吗？', {
    time: 0 ,//不自动关闭
    btn: ['必须啊', '不必了'],
    yes: function(index){
      var id=1;
      $.ajax({
        type: "POST",
        url: "<?php echo url('cate/emptied'); ?>",
        data: {
        'id':id,
        },
        dataType: "json",
        success: function(data){
          var data=eval("("+data+")");

        if (data.status == 1){

          parent.layer.msg('当前表清除成功！！！！！',{icon:1,time:1000,},function(){parent.location.reload();});
        
        }
        else{
        parent.layer.msg('当前表清除失败！！！！！~！',{icon:2,time:1000,},function(){parent.location.reload();});
        }
        }
      });
    }
  });
}
</script>
</body>
</html>